VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOCategoria"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private mvarConnection As utilConexion 'local copy

Public Property Set Connection(ByVal vData As utilConexion)
'used when assigning an Object to the property, on the left side of a Set statement.
'Syntax: Set x.Connection = vData
    Set mvarConnection = vData
End Property


Public Function guardarNuevo(bean As bCategoria) As Boolean
On Error GoTo hnderr

Dim sql As String
sql = "INSERT INTO categoria(ncodigo, sdescorta, sdeslarga, nestado) "
sql = sql + "VALUES (nextval('seq_categoria'),'"
sql = sql + bean.sDescripcionCorta + "','" + bean.sDescripcionLarga + "',"
sql = sql + CStr(bean.bEstado.nCodigo) + ")"
mvarConnection.Connection.Execute sql
guardarNuevo = True

hnderr:
If Err.Number = 0 Then Exit Function
guardarNuevo = False
cloneError Err
End Function


Public Function eliminar(bean As bCategoria) As Boolean
On Error GoTo hnderr
Dim sql As String
sql = "UPDATE categoria SET sdescorta='" + bean.sDescripcionCorta + "' , "
sql = sql + " sdeslarga ='" + bean.sDescripcionLarga + "' , "
sql = sql + " nestado = " + CStr(Val(bean.bEstado.nCodigo)) + " "
sql = sql + " WHERE ncodigo= " + CStr(bean.nCodigo)

mvarConnection.Connection.Execute sql

eliminar = True
hnderr:
If Err.Number = 0 Then Exit Function
eliminar = False
cloneError Err
End Function




Public Function actualizar(bean As bCategoria) As Boolean
On Error GoTo hnderr
Dim sql As String
sql = "UPDATE categoria SET sdescorta='" + bean.sDescripcionCorta + "' , "
sql = sql + " sdeslarga ='" + bean.sDescripcionLarga + "' , "
sql = sql + " nestado = " + CStr(Val(bean.bEstado.nCodigo)) + " "
sql = sql + " WHERE ncodigo= " + CStr(bean.nCodigo)
mvarConnection.Connection.Execute sql
actualizar = True
hnderr:
If Err.Number = 0 Then Exit Function
actualizar = False
cloneError Err
End Function

Public Function getBean(ByVal bean As bCategoria) As bCategoria
On Error GoTo hnderr

Dim result As bCategoria
Dim sql As String
Dim rst As New Recordset
sql = "SELECT c.ncodigo,sdescorta,sdeslarga,nestado , e.sDescripcion as sestado "
sql = sql + "FROM categoria c INNER JOIN estado e "
sql = sql + "ON c.nestado=e.nCodigo "
sql = sql + "WHERE c.ncodigo =" + CStr(bean.nCodigo)

rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

If Not rst.EOF Then
    Set result = New bCategoria
    If Not IsNull(rst.Fields("nCodigo")) Then result.nCodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then result.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then result.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("nestado")) Then result.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then result.bEstado.sDescripcion = rst.Fields("sestado").value
End If
Set getBean = result
hnderr:
If Err.Number = 0 Then Exit Function
cloneError Err
End Function
Public Function getLista(bean As bCategoria) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bCategoria

sql = "SELECT ncodigo , sdescorta, sdeslarga , nestado , sestado "
sql = sql + "FROM proc_categoria_select()"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

While Not rst.EOF
    Set record = New bCategoria
    If Not IsNull(rst.Fields("nCodigo")) Then record.nCodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sDescripcion = rst.Fields("sestado").value
    rst.MoveNext
    list.Add record
Wend
Set getLista = list

hnderr:
If Err.Number = 0 Then Exit Function
cloneError Err
End Function


